<?php
/**
 * Created by PhpStorm.
 * User: jochen
 * Date: 2017/1/5
 * Time: 下午4:38
 */

namespace EWeiLink\JuPai;

use Illuminate\Contracts\Support\Jsonable;
use Illuminate\Contracts\Support\Arrayable;
use Jenssegers\Mongodb\Eloquent\Model;

class JuPaiEntity implements Jsonable, Arrayable, \ArrayAccess
{
    use BaseEntityTrait;

    /**
     * JuPaiEntry constructor.
     * @param Model $customer
     */
    public function __construct($customer = null)
    {
        if (!is_null($customer) && isset($customer->socailInfo)) {
            $this->origin = array_get(
                $customer->socialInfo, 'jupai',  // 获取socialInfo中的jupai字段
                $this->createByDefault()  // 找不到值，创建默认实体
            );
        }

    }

    protected function createByDefault()
    {
        return [
            'id' => 0,
            'name' => '',
            'phone' => '',
        ];
    }

}